package servlet.Visitor;

import service.person.PersonService;
import service.person.PersonServiceImpl;
import service.visitor.VisitorService;
import service.visitor.VisitorServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class DelectVisitor extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

        if(request.getSession().getAttribute("userloginflag")==null){
            request.getRequestDispatcher("/index.jsp").forward(request, response);
        }
        else {
            if (request.getParameter("visitors_id")==null ||request.getParameter("visitors_id")==""){
                request.getRequestDispatcher("/admin/error/error404.jsp").forward(request, response);
                return;
            }else {
                VisitorService visitorService = new VisitorServiceImpl();
                int visitors_id = Integer.parseInt(request.getParameter("visitors_id"));
                int i = visitorService.DelectVisitors(visitors_id);
                if(i != 0)
                    request.setAttribute("message", "删除成功");
                else
                    request.setAttribute("message", "删除失败");
                request.getRequestDispatcher("VisitorInfo").forward(request, response);
                return;
            }
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}
